package com.meloneatingmasses.lowcodeplatform.service.impl;

import com.meloneatingmasses.lowcodeplatform.dao.ContentRepository;
import com.meloneatingmasses.lowcodeplatform.po.ContentJson;
import com.meloneatingmasses.lowcodeplatform.service.ContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ContentServiceImpl implements ContentService {

    @Autowired
    private MongoTemplate mongoTemplate;

    @Override
    public ContentJson insert(ContentJson dbObject) {
        ContentJson coll = mongoTemplate.insert(dbObject, "coll");
        return coll;
    }

    @Override
    public ContentJson getContents(String id) {
        Query query = null;
        ContentJson contentJsons = null;
        if (id != null) {
//            query = Query.query(Criteria.where("result_json._id").is(id));
            contentJsons = mongoTemplate.findById(id, ContentJson.class);
        }
        return contentJsons;
    }
}
